<template>
    <div class="app-container">
        <el-card shadow="never">
            <!-- 条件查询 -->
            <el-form v-show="showSearch" ref="queryForm" :model="queryParams" label-width="120px" @keyup.enter.native="submitSearch" @submit.native.prevent>
                <el-row>
                    <el-col :md="6" :sm="12" v-if="!queryObj.spec_id">
                        <el-form-item label="专家用户:" prop="user_id.value">
                            <SelectPage v-model="queryParams.user_id.value" placeholder="请选择专家用户"
                                        :url="'/admin/user/selectPage'" show_field="nickname" show_id="uid" query_field="uid" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :md="6" :sm="12" v-if="!queryObj.spec_id">
                        <el-form-item label="专家名称:" prop="spec_id.value">
                            <SelectPage v-model="queryParams.spec_id.value" :url="'/admin/sq.specialist/selectPage'" show_field="realname" show_id="id" query_field="id" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :md="queryObj.spec_id ? 12 : 6" :sm="12">
                        <el-form-item label="支付用户:" prop="pay_user_id.value">
                            <SelectPage v-model="queryParams.pay_user_id.value" placeholder="请选择支付用户"
                                        :url="'/admin/user/selectPage'" show_field="nickname" show_id="uid" query_field="uid" :multiple="false" />
                        </el-form-item>
                    </el-col>
                    <el-col :md="queryObj.spec_id ? 12 : 6" :sm="12">
                        <el-form-item label="支付金额:" prop="money.value">
                            <el-row>
                                <el-col :span="11">
                                    <el-input v-model="startMoney" placeholder="支付金额" clearable @input="onInputMoney1" />
                                </el-col>
                                <el-col :span="2">
                                    <div style="text-align: center">-</div>
                                </el-col>
                                <el-col :span="11">
                                    <el-input v-model="endMoney" placeholder="支付金额" clearable @input="onInputMoney2" />
                                </el-col>
                            </el-row>
                        </el-form-item>
                    </el-col>
                    <el-col :md="queryObj.spec_id ? 12 : 6" :sm="12">
                        <el-form-item label="备注信息:" prop="remark.value">
                            <el-input v-model="queryParams.remark.value" placeholder="请输入备注信息" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :md="queryObj.spec_id ? 12 : 6" :sm="12">
                        <el-form-item label="支付时间:" prop="pay_time.value">
                            <el-date-picker
                                v-model="queryParams.pay_time.value"
                                type="datetimerange"
                                range-separator="至"
                                start-placeholder="开始"
                                end-placeholder="结束"
                                align="right"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            >
                            </el-date-picker>
                          </el-form-item>
                    </el-col>
                    <el-col :md="queryObj.spec_id ? 12 : 6" :sm="12">
                        <el-form-item label="下单时间:" prop="create_time.value">
                            <el-date-picker
                                v-model="queryParams.create_time.value"
                                type="datetimerange"
                                range-separator="至"
                                start-placeholder="开始"
                                end-placeholder="结束"
                                align="right"
                                value-format="yyyy-MM-dd HH:mm:ss"
                            >
                            </el-date-picker>
                          </el-form-item>
                    </el-col>
                    <el-col :md="queryObj.spec_id ? 12 : 6" :sm="12">
                        <el-form-item class="ele-text-right" label-width="50px">
                            <el-button type="primary" size="mini" @click="submitSearch" icon="el-icon-search" class="ele-btn-icon">搜索 </el-button>
                            <el-button @click="resetQuery" size="mini" icon="el-icon-refresh">重置</el-button>

                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>


            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5" v-if="false">
                    <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="open" v-hasPermi="api.add">添加</el-button>
                </el-col>
                <el-col :span="1.5" v-if="false">
                    <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="api.delete">删除</el-button>
                </el-col>
                <el-col :span="1.5">
                    <el-button type="warning" plain icon="el-icon-download" size="mini" v-loading="exportLoading" @click="handleExport" v-hasPermi="api.export">导出</el-button>
                </el-col>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="initIndex" :columns="columns" printId="#quickadmin"></right-toolbar>
            </el-row>

            <!-- 列表 -->
            <qa-table
                :source="tableData"
                :columns="columns"
                :selection="true"
                :loading="loading"
                @sortChange="sortChange"
                @statusChange="statusChange"
                @selectionChange="selectionChange"
                id="quickadmin"
            >
                <template v-slot:action>
                    <el-table-column label="操作" width="180" v-if="false">
                        <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleEdit(scope.row)" v-hasPermi="api.edit">编辑</el-button>
                            <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleDetail(scope.row)" v-hasPermi="api.find">详情</el-button>
                            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="api.delete">删除</el-button>
                        </template>
                    </el-table-column>
                </template>
            </qa-table>

            <!-- 分页 -->
            <pagination :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="initIndex" />
        </el-card>

        <!-- 编辑弹窗 -->
       <el-dialog :title="!disabled ? ( findFormData[pk] ? '编辑' : '添加' ) : '详情'" :visible="editOpen" :before-close="beforeClose" destroy-on-close>
            <EditForm ref="editForm" :findFormData="findFormData" :disabled="disabled" @submitForm="submitForm" :editFormParams="editFormParams" @editFormCancel="beforeClose" />
        </el-dialog>
    </div>
</template>

<script>
import { curdMixin } from '@/mixins/curdMixin'
import EditForm from './EditFormCom'
export default {
    name: 'Curd',
    mixins: [curdMixin],
    components: { EditForm },
    props: {
        queryObj: {
            type: Object,
            default: () => {
                return {
                    spec_id: ''
                }
            }
        }
    },
    data() {
        return {
            // table结构
            columns: [
                {
                    visible: true,
                    label: '编号',
                    prop: 'id',
                    width: 60
                },
                {
                    visible: true,
                    label: '专家用户',
                    prop: 'myUser.nickname',
                },
                {
                    visible: true,
                    label: '专家名称',
                    prop: 'sqSpecialist.realname',
                },
                {
                    visible: true,
                    label: '支付用户',
                    prop: 'payMyUser.nickname',
                },
                {
                    visible: true,
                    label: '支付金额',
                    prop: 'money',
                },
                {
                    visible: true,
                    label: '备注信息',
                    prop: 'remark',
                    width: 120,
                    overflow: true
                },
                {
                    visible: true,
                    label: '状态',
                    prop: 'status',
                    component:'QuickAdminTextColor',
                    formatter: (prop, row) => {
                        let type = ''
                        switch (prop) {
                            case 1:
                                type = 'success'
                                break
                            case 2:
                                type = 'warning'
                                break
                            case 3:
                                type = 'info'
                                break
                            case 4:
                                type = 'primary'
                                break
                            case 5:
                                type = 'primary'
                                break

                        }
                        return {
                            value: prop,
                            type: type,
                            text: row.status_text,
                        }
                    },
                },
                {
                    visible: true,
                    label: '支付成功时间',
                    prop: 'pay_time',
                    width: 120,
                    overflow: true
                },
                {
                    visible: true,
                    label: '下单时间',
                    prop: 'create_time',
                    width: 120,
                    overflow: true
                },
                {
                    visible: true,
                    label: '更新时间',
                    prop: 'update_time',
                    width: 120,
                    overflow: true
                }
            ],
            // 接口地址
            api: {
                index: `/admin/sq.specialist_order/index`,
                find: `/admin/sq.specialist_order/find`,
                add: `/admin/sq.specialist_order/add`,
                edit: `/admin/sq.specialist_order/edit`,
                delete: `/admin/sq.specialist_order/delete`,
                export: `/admin/sq.specialist_order/export`,
                status: `/admin/sq.specialist_order/status`
            },
            editFormParams: {},
            // 搜索表单是否展开
            searchExpand: false,
            // 查询参数
            queryParams: {
                user_id: { value:undefined, op: '='},
                spec_id: { value:undefined, op: '='},
                pay_user_id: { value:undefined, op: '='},
                money: { value:[], op: 'range'},
                remark: { value:undefined, op: '%like%'},
                pay_time: { value:[], op: 'range'},
                create_time: { value:[], op: 'range'},
            },
            status:[
               { label: "待付款", value: 1 },
               { label: "付款中", value: 2 },
               { label: "已付款", value: 3 },
               { label: "已取消", value: 4 },
               { label: "已拒绝", value: 5 },
            ],
            startMoney: '',
            endMoney: '',
            tableIsJoinLoad: false
        }
    },
    methods: {
        onInputMoney1(e) {
            let arr = this.queryParams.money.value
            arr[0] = this.startMoney * 100
            this.$set(this.queryParams.money, 'value', arr)
        },
        onInputMoney2(e) {
            let arr = this.queryParams.money.value
            arr[1] = this.endMoney * 100
            this.$set(this.queryParams.money, 'value', arr)
        }
    },
    created() {
        if (this.queryObj.spec_id) {
            this.$set(this.queryParams.spec_id, 'value', this.queryObj.spec_id)
            this.columns[1].visible = false
            this.columns[2].visible = false
        }
        this.initIndex()
    }
}
</script>
